package 语雀题目21至55;

/**
 * ClassName: 莱布尼茨公式求兀
 * Package: 语雀21至40
 * Description:
 *
 * @Author fjorid
 * @Create 2025/1/6 19:17
 * @Version 1.0
 */
public class 莱布尼茨公式求兀24 {
    public static void main(String[] args) {
        int PorM = 1,n = 1;
        int denominator = 1;
        int a = -1;
         double each = 0.0, sum = 0.0,pi=0.0,count=0.0;
        while (true){
            each = PorM*1.0/denominator;//发现只要在一个循环中先算each，变化的量正负号，分母等按规律变化，下一轮在求each就好。
            PorM *= a;
            n++;
            denominator = 2*n-1;
            sum += each;
            pi = 4*sum;
            count++;
            System.out.println(pi+","+count);



        }
    }


}
